//获取本地数据
function getData(name) {
    var local = localStorage.getItem(name);
    if (local != null) {
        return JSON.parse(local);
    } else {
        return [];
    }
}

//添加本地数据
function saveData(data) {
    localStorage.setItem('resigter', JSON.stringify(data));
}

//提交修改信息 修改本地数据
// $('#user-btn').click(function () {
//     var local = getData('resigter');
//     local.forEach(() => {

//     })
//     console.log(local);
// })

//
var book = getData('userPage');
console.log(book);


book.forEach(v => {
    $('#goods').append(`<tr class="hebing">
    <td colspan="7">
        订单号：1050348163 成交时间：${v.date}
    </td>
</tr>
<tr class="lstr">
    <td>
        <p>${v.good_name}</p>
    </td>
    <td>${v.clickPrice}</td>
    <td>${v.amount}</td>
    <td>北京总部</td>
    <td>${v.totalPrice}</td>
    <td>交易成功</td>
    <td></td>
</tr>`)
});




// 页面一打开 省份数据需要渲染在页面上
$.ajax({
    url: "https://www.fastmock.site/mock/a66f36fea599784156aa8e97d31fb96f/data/getAllProvices",
    success: function (data) {
        var provices = data.provices
        provices.forEach(p => {
            var $newOption = $(`<option value="${p.ProID}">${p.name}</option>`);
            $('#proviceSelect').append($newOption);
        });
    }
});

//给省份设置change事件：选择项改变时触发
$('body').on('change', '#proviceSelect', function () {
    //选择的省份id

    var Pid = $(this).val();
    //拿到城市数据并根据pid进行过滤
    $.ajax({
        url: 'https://www.fastmock.site/mock/a66f36fea599784156aa8e97d31fb96f/data/getAllCities',
        success: function (data) {
            var cities = data.cities;
            var cs = cities.filter(c => c.ProID == Pid);
            //渲染数据
            $('#citySelect').html('<option>请选择城市</option>');
            cs.forEach(c => {
                var $newOption = $(`<option value="${c.CityID}">${c.name}</option>`);
                $('#citySelect').append($newOption);
            });
        }
    })
});

//给城市设置change事件，选择项改变时触发
$('body').on('change', '#citySelect', function () {
    //选择的城市id
    var Cid = $(this).val();
    //拿到街道数据并根据cid进行过滤
    $.ajax({
        url: 'https://www.fastmock.site/mock/a66f36fea599784156aa8e97d31fb96f/data/getAllStreets',
        success: function (data) {
            var streets = data.streets;
            var ss = streets.filter(s => s.CityID == Cid);
            //渲染数据
            $('#streetSelect').html('<option>请选择街道</option>');
            ss.forEach(s => {
                var $newOption = $(`<option value="">${s.name}</option>`);
                $('#streetSelect').append($newOption);
            });
        }
    })
});
